package com.example.carbon.server.info;

import com.alibaba.fastjson2.JSON;
import com.example.carbon.dao.ProductModelDao;
import com.example.carbon.pojo.dto.PageLimit;
import com.example.carbon.pojo.vo.TableData;
import com.example.carbon.server.ProductModelServerInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ProductModelServer implements ProductModelServerInfo {
    @Resource
    ProductModelDao productModelDao;

    @Override
    public String selectAllInfo(PageLimit pageLimit, String modelName) {
        try {
            TableData tableData = new TableData<>(productModelDao.selectAllInfo(pageLimit, modelName), productModelDao.selectAllCount(modelName));
            return JSON.toJSONString(tableData);
        } catch (Exception e) {
            log.info(e.getMessage());
            return null;
        }
    }

    @Override
    public String selectInfoById(int id) {
        try {
            return JSON.toJSONString(productModelDao.selectModelById(id));
        } catch (Exception e) {
            log.info(e.getMessage());
            return null;
        }
    }

    @Override
    public String selectAllModelType() {
        try {
            return JSON.toJSONString(productModelDao.selectAllModelName());
        }catch (Exception e){
            log.info(e.getMessage());
            return null;
        }
    }


}
